package il.ac.tau.cvws.scrabblesidekick.client.ui.view.camera;

import il.ac.tau.cvws.scrabblesidekick.client.app.controller.CameraController;
import il.ac.tau.cvws.scrabblesidekick.client.ui.view.dialog.ProgressDialogHandler;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;

/* A task to handle taking high-quality pictures.
 * The task displays a progress bar to the user and sends the high-quality
 * image for handling by the controller, in the background.
 */
public class PictureTakenTask extends AsyncTask<Bitmap, Void, Void> 
{
	private int _screenWidth;
	private int _screenHeight;
	
	private ProgressDialogHandler _dialogHandler;
	private CameraController _controller;
	private Context _context;
	
	public PictureTakenTask(int screenWidth, int screenHeight, Context context, CameraController controller, ProgressDialogHandler dialogHandler)
	{
		_screenWidth	= screenWidth;
		_screenHeight	= screenHeight;
		
		_dialogHandler	= dialogHandler;
		_controller		= controller;
		_context		= context;
	}
	
	/* Send the image to the controller for handling. This takes place in a
	 * background thread.
	 */
	@Override
	protected Void doInBackground(Bitmap... params)
	{	
		_controller.handleHighQualityImage(_screenWidth, _screenHeight, params[0]);
		
		return null;
	}
	
	/* Displays a progress bar dialog to the user. This takes place on the UI thread.
	 */
	@Override                		
	public void onPreExecute() 
	{
		_dialogHandler.showProgressBar(_context);
	}
}
